package ext.acae2.change.datautility;


import java.util.List;

import wt.fc.Persistable;
import wt.util.WTException;

import com.ptc.core.components.descriptor.ModelContext;
import com.ptc.core.components.factory.dataUtilities.StringDataUtility;
import com.ptc.core.components.rendering.AbstractGuiComponent;
import com.ptc.core.components.rendering.guicomponents.GUIComponentArray;
import com.ptc.core.components.rendering.guicomponents.TextBox;
import com.ptc.core.components.rendering.guicomponents.TextDisplayComponent;
import com.ptc.core.ui.resources.ComponentMode;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.acae2.change.autonumber.ECNNumberGenerator;

/**
 * @desription TODO
 * @author cnie
 * @date 2013-5-10 下午11:04:25
 */
public class ECNNumberDataUtility extends StringDataUtility {

	@Override
	public Object getDataValue(String columnName, Object obj,
			ModelContext modelcontext) throws WTException {
		String ecnType = (String)((List)modelcontext.getNmCommandBean().getComboBox().get("createType")).get(0);
		Object component = super.getDataValue(columnName, obj, modelcontext);
		ComponentMode mode = modelcontext.getDescriptorMode();
		String cName = ((AbstractGuiComponent) component).getColumnName();
		if (mode != ComponentMode.CREATE) {
			return component;
		}
		if ("number".equals(columnName)) {
			NmCommandBean commandBean = modelcontext.getNmCommandBean();
			Persistable po = commandBean.getPrimaryOid().getWtRef().getObject();
			GUIComponentArray componentArray = new GUIComponentArray();
			TextDisplayComponent textDisCom = new TextDisplayComponent("(已生成)");
			textDisCom.setValue("(已生成)");
			componentArray.addGUIComponent(textDisCom);
			TextBox nInput = new TextBox();
			nInput.setInputType("hidden");
			nInput.setColumnName(cName);
			String ecnNumber = ECNNumberGenerator.getECNNumber(po);
			nInput.setValue(ecnNumber);
			componentArray.addGUIComponent(nInput);
			return componentArray;
		}
		return null;
	}

	
}
